<template>
  <div>
    <el-menu
      default-active="2"
      class="el-menu-vertical-demo"
      @select="selectHandler"
      style="border: none;">
      <el-submenu index="1" v-for="(item, i) in menuList" :key="i" :index="String(i + 1)">
        <template slot="title">
          <span>{{item.title}}</span>
        </template>
        <el-menu-item-group>
          <el-menu-item v-for="(select) in item.selections" :key="select.url" :index="select.url">{{ select.title }}</el-menu-item>
        </el-menu-item-group>
      </el-submenu>
    </el-menu>
  </div>
</template>

<script>
export default {
  name: "Navigation",
  data() {
    return {
      menuList: [{
        title: '选项一',
        selections: [{
          url: '/hello',
          title: 'a'
        },{
          url: '/b',
          title: 'b'
        },{
          url: '/c',
          title: 'c'
        }]
      },{
        title: '选项二',
        selections: []
      }]
    }
  },
  methods: {
    selectHandler(path) {
      for(let i = 0; i < this.menuList.length; i++) {
        for(let k = 0; k < this.menuList[i].selections.length; k++) {
          if(this.menuList[i].selections[k].url === path) {
            let that = this;
            that.$eventBus.$emit('addTab', this.menuList[i].selections[k])
          }
        }
      }
    }
  }
}
</script>

<style>
  .el-menu .el-menu-item {
    padding: 0;
    text-align: left;
    width: 100%;
  }
  .el-submenu__title {
    padding: 0;
    text-align: left;
    width: 100%;
  }
</style>
